Skip to content

fix(mermaid): emit mermaid diagrams in a raw html block - #14767

Merged
cderv merged 6 commits into
quarto-dev:mainfrom
mcanouil:fix/issue14765
Oct 19, 2026
Merged

cderv merged 6 commits into
quarto-dev:mainfrom
mcanouil:fix/issue14765

Conversation

@mcanouil

@mcanouil mcanouil commented Aug 12, 2026 •

Copy link
Copy Markdown
Collaborator

Description

A mermaid diagram with its own --- configuration block hid the rest of the document, and ojs cells after it never ran.
The diagram source went into the intermediate markdown as a bare <pre>, so its closing --- was read as the start of YAML front matter.

The <pre> now goes inside a {=html} raw block, which the markdown splitter does not look into.
The HTML output is the same, because Pandoc already read the bare <pre> as an HTML raw block.

pandocBlock now sizes that fence from the longest backtick run in the content, not the first one.
Before, a diagram with a single backtick in one label and a line starting with three backticks later on closed the raw block early.

The commented-out tooltip code is gone, since Mermaid 11.12 creates .mermaidTooltip itself.

The smoke-all test covers both cases, and the backtick case fails when the fence change is reverted.
A Playwright test checks that the SVG keeps aria-roledescription, <title> from accTitle and <desc> from accDescr in Chromium, Firefox and WebKit.
It guards Mermaid's own accessibility output, which the raw block must keep.

Closes #14765

Checklist

I have (if applicable):

  • referenced the GitHub issue this PR closes
  • updated the appropriate changelog in the PR
  • ensured the present test suite passes
  • added new tests
  • created a separate documentation PR in Quarto's website repo and linked it to this PR
AI-assisted PR
  • AI tool used: Claude Code
  • Codebase grounding: local clone
  • Human review: I have reviewed, tested, and verified the AI-generated content before submitting.

Note: autonomous AI agents submitting PRs without human oversight are not permitted — see the Code of Conduct.

@posit-snyk-bot

posit-snyk-bot commented Aug 12, 2026 •

Copy link
Copy Markdown
Collaborator

✅ Snyk checks have passed. No issues have been found so far.

Status Scan Engine Critical High Medium Low Total (0)
✅ Open Source Security 0 0 0 0 0 issues
✅ Licenses 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

@mcanouil mcanouil changed the title fix: emit mermaid diagrams in a raw html block fix(mermaid): emit mermaid diagrams in a raw html block Aug 12, 2026
A bare `---` line in a mermaid diagram, such as the closing delimiter of
mermaid's own front matter, was read as a YAML front matter delimiter when
quarto split the document into cells. It hid the rest of the document, so
`ojs` cells placed after a mermaid diagram never reached the ojs compiler
and rendered as plain code.

Wrapping the `<pre>` element in a `{=html}` raw block keeps the cell
splitter out of the diagram source. Pandoc's markdown reader already
produced the same `RawBlock (Format "html")` for the bare html block, so
the rendered output does not change.

Also removes the commented-out mermaid tooltip code. Its note said
"removed until we use mermaid 10.0.0"; the bundled runtime is 11.12.0 and
mermaid now creates the `.mermaidTooltip` div itself.

@cderv cderv left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fix. I checked that the smoke test fails when either the raw block or the fence sizing change is reverted, and the rendered HTML for other mermaid diagrams (blank lines, cross-ref with caption, revealjs) is unchanged apart from whitespace.

I'll push a small adjustment before merging: a unit test for the longest-run fence sizing in pandocBlock, covering the : div fences too as they go through the same code. No need to push anything meanwhile.

pandocBlock is shared by code fences and div fences, but the smoke test
only reaches the backtick path through a mermaid cell. These unit tests
pin both delimiters directly: content with a short run first and a
longer run later must get a fence longer than the longest run.

Both cases fail with the previous first-run sizing.
@cderv
cderv merged commit da49117 into quarto-dev:main Oct 19, 2026
51 checks passed
@mcanouil
mcanouil deleted the fix/issue14765 branch October 19, 2026 14:20
cderv added a commit that referenced this pull request Oct 19, 2026
Categories containing a backtick run longer than the first one, or any
backslash, rendered broken in the page title block. A Windows path failed
the whole render with "couldn't read native", and a backslash sequence
such as \n was silently changed. pandocNativeStr now sizes the inline-code
delimiter from the longest backtick run and escapes backslashes before
quotes, so the text reaches pandoc as written.

- Size the inline-code delimiter from the longest backtick run
- Escape backslashes in the pandoc-native string literal
- Add unit tests for backtick and backslash input

See #14767
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Weird Bug: mermaid config option breaks OJS

3 participants